#!/bin/env bash

function install_arch_x11vnc {
    IS_CHANGED=$(cat /usr/lib/systemd/system/x11vnc.service | grep '# OneKeyMan')
    if [ "$IS_CHANGED" != "" ]; then
        echo '已经安装了x11vnc'
        return
    fi

    echo '安装x11vnc服务'
    yay -S x11vnc


    echo '设置服务连接密码'
    x11vnc -storepasswd /etc/x11vnc.pass

    echo '配置x11vnc.service'
    sed -E -i 's#(11vnc)#/\1 -auth /var/run/lightdm/root/:0 -forever -rfbauth /etc/x11vnc.pass -rfbport 5900 -shared \# OneKeyMan\nUser=root\n\n[Install]\nWantedBy=multi-user\.target#' /usr/lib/systemd/system/x11vnc.service
    sudo systemctl daemon-reload

    echo '启动x11vnc服务'
    sudo systemctl --now enable x11vnc

    echo 'x11vnc服务安装完毕'
}


install_arch_x11vnc